package dao

import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import javax.inject.Inject
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

class WechatMemberDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) extends
  HasDatabaseConfigProvider[JdbcProfile] {


  import utils.MyPostgresProfile.api._

  type MyRow = WechatMemberRow
  val table = WechatMember

  def insert(row: MyRow) = {
    db.run(table += row)
  }

  def selectAll = db.run(table.result.map(_.toList))

  def phoneExist(account: String) = db.run(table.
    filter(_.phone === account).exists.result)

  def deleteByPhone(phone: String): Future[Unit] = db.run(table.filter(_.phone === phone).delete).map(_ => ())


}
